﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace Arkanoid
{
    class Bloco
    {
        Texture2D texture;
        Vector2 position;
        Rectangle size;
        bool Visible;

        public int level = 0;
        public int pontos = 0;
        public int tileBlocos = 0;

        public static List<Bloco> meuTile = new List<Bloco>();


        public  int[, ,] mapa = { {
                            {8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
                            {8, 8, 1, 1, 1, 1, 8, 3, 8, 8, 8, 5, 5, 8, 8, 0, 0, 0, 8, 8},
                            {8, 8, 8, 1, 1, 8, 8, 8, 4, 4, 8, 8, 8, 8, 0, 0, 0, 0, 0, 8},
                            {8, 8, 1, 1, 1, 1, 8, 8, 4, 4, 4, 4, 8, 8, 8, 0, 0, 0, 8, 8}, 
                            {8, 8, 8, 8, 8, 8, 5, 8, 8, 8, 8, 8, 8, 0, 8, 8, 0, 8, 8, 8},
                            {8, 8, 8, 2, 8, 4, 8, 3, 8, 8, 8, 8, 3, 8, 8, 8, 8, 8, 8, 8},
                            {8, 8, 2, 2, 2, 8, 6, 8, 3, 3, 3, 3, 8, 8, 7, 7, 7, 7, 7, 8},
                            {8, 2, 2, 2, 2, 2, 8, 8, 3, 3, 3, 3, 8, 8, 7, 8, 8, 8, 8, 8},
                            {8, 8, 2, 2, 2, 8, 8, 3, 8, 8, 8, 8, 3, 8, 8, 8, 8, 6, 6, 8},
                            {8, 8, 8, 2, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 8, 6, 6, 8}
                        },

                        { 
                            {8, 8, 8, 8, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 8, 8, 8, 8},
                            {8, 8, 8, 8, 8, 9, 9, 8, 8, 8, 8, 8, 8, 9, 9, 8, 8, 8, 8, 8}, 
                            {8, 8, 8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 8, 8, 8, 8},
                            {8, 8, 2, 2, 2, 2, 0, 0, 0, 2, 2, 0, 0, 0, 2, 2, 2, 2, 8, 8}, 
                            {8, 8, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 2, 2, 8, 8},
                            {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2}, 
                            {1, 1, 8, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 8, 8, 2, 2},
                            {1, 1, 8, 8, 1, 1, 8, 8, 8, 8, 8, 8, 8, 8, 1, 1, 8, 8, 2, 2}, 
                            {1, 1, 8, 8, 8, 8, 1, 8, 8, 8, 8, 8, 8, 1, 8, 8, 8, 8, 2, 2},
                            {8, 8, 8, 8, 8, 8, 1, 1, 1, 8, 8, 1, 1, 1, 8, 8, 8, 8, 8, 8} 
                        },

                        { 
                            {8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
                            {8, 3, 5, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 4, 8}, 
                            {8, 3, 5, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 6, 4, 8},
                            {8, 3, 5, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 6, 4, 8}, 
                            {8, 3, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 4, 8},
                            {8, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 8}, 
                            {8, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8},
                            {8, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 8}, 
                            {8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 8},
                            {8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 8} 
                        },

                        { 
                            {8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
                            {8, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 8}, 
                            {8, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 8},
                            {8, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 8}, 
                            {8, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 8},
                            {8, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 8}, 
                            {8, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 8},
                            {8, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 8}, 
                            {8, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 8},
                            {8, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 8} 
                        },

                        { 
                            {8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
                            {8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 8}, 
                            {8, 2, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 2, 8},
                            {8, 2, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 2, 8}, 
                            {8, 2, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 2, 8},
                            {8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 8}, 
                            {8, 2, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 2, 8},
                            {8, 2, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 2, 8}, 
                            {8, 2, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 2, 8},
                            {8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 8} 
                        },

                       
                        };


        public Bloco(Texture2D texture, Vector2 position, Rectangle size) 
        {
            this.texture = texture;
            this.position = position;
            this.size = size; 
            this.Visible = true;
            meuTile.Add(this);     
        }

        public void Update() 
        {
            for (int i = 0; i < meuTile.Count; i++)
            {
                meuTile[i].size.X = (int)meuTile[i].position.X;
                meuTile[i].size.Y = (int)meuTile[i].position.Y; 
            }
        }

        public void Colisao(Bola bola) 
        {
            for (int i = 0; i < meuTile.Count; i++)
            {
                if (bola.Size.Intersects(meuTile[i].size) && meuTile[i].Visible)
                {
                    bola.VelocidadeY *= -1;
                    pontos = pontos + 2;
                    tileBlocos++;
                    meuTile[i].Visible = false;
                    meuTile.RemoveAt(i); 

                    } 
                }
            }
       

        public void Draw(SpriteBatch spriteBatch)
        {
             for (int i = 0; i < meuTile.Count; i++)
             {
                 if (meuTile[i].Visible)
                 {
                     spriteBatch.Draw(meuTile[i].texture, meuTile[i].size, Color.White);
                 }
             }

        }
 



    }
}
